var $cookie = (key, value) => {
    if (arguments.length == 1) {
        return $cookie.get(key)
    } else {
        $cookie.set(key, value)
    }
}

// 设置cookie
$cookie.set = (key, value) => {
    var Days = 30
    var exp = new Date()
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000)
    document.cookie = key + '=' + escape(value) + ';expires=' + exp.toGMTString()
}

$cookie.get = (key) => {
    var reg = new RegExp('(^| )' + key + '=([^;]*)(;|$)')
    var arr = document.cookie.match(reg)
    if (arr) {
        return unescape(arr[2])
    } else {
        return null
    }
}
// 删除cookie
$cookie.remove = (key) => {
    var exp = new Date()
    exp.setTime(exp.getTime() - 1)
    var cval = this.get(key)
    if (cval != null) {
        document.cookie = key + '=' + cval + ';expires=' + exp.toGMTString()
    }
}

export default $cookie